package useTask.hdfs_to_hbase.hdfsMode;

import org.apache.hadoop.hbase.client.Put;

import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;


// 输出数据格式要满足hbase的数据格式
public class mapper extends Mapper<LongWritable, Text, ImmutableBytesWritable, Put> {
    // 行建,行值 --> ImmutableBytesWritable, Value
    ImmutableBytesWritable Key = new ImmutableBytesWritable();
    @Override
    protected void map(LongWritable key, Text value, Mapper<LongWritable, Text, ImmutableBytesWritable, Put>.Context context) throws IOException, InterruptedException {
        String str = value.toString();
//        2305151131,李美玲,1,68,80,79,60,87,94,94,64
//        学号,姓名,性别,Java程序设计Ⅰ,Linux操作系统,思想道德与法治+形势与政策Ⅰ,体育Ⅰ,心理健康教育,信息技术Ⅰ,职场通用英语Ⅰ,高等数学Ⅰ
        if(str!=null && !"".equals(str.trim())){
            String[] split = str.split(",");
            byte[] row_key = split[0].getBytes();
            Key.set(row_key);
            Put Value = new Put(row_key);
            Value.addColumn("c1".getBytes(),"name".getBytes(),split[1].getBytes());
            Value.addColumn("c1".getBytes(),"sex".getBytes(),split[2].getBytes());
            Value.addColumn("c1".getBytes(),"java".getBytes(),split[3].getBytes());
            Value.addColumn("c1".getBytes(),"linux".getBytes(),split[4].getBytes());
            Value.addColumn("c1".getBytes(),"political".getBytes(),split[5].getBytes());
            Value.addColumn("c1".getBytes(),"sport".getBytes(),split[6].getBytes());
            Value.addColumn("c1".getBytes(),"mind".getBytes(),split[7].getBytes());
            Value.addColumn("c1".getBytes(),"comValueer".getBytes(),split[8].getBytes());
            Value.addColumn("c1".getBytes(),"english".getBytes(),split[9].getBytes());
            Value.addColumn("c1".getBytes(),"math".getBytes(),split[10].getBytes());
    
            context.write(Key,Value);
        }
    }
}
